<!--执行中-策略-->
<template>
  <!-- 列表 -->
  <list class="list" :loadmoreoffset="50" @loadmore="httpTrustsLoading">
  
    <!--刷新-->
    <refresh class="refresh" @refresh="httpTrusts" :display="isRefresh ? 'show' : 'hide'">
      <loading-indicator class="load text1"></loading-indicator>
    </refresh>

    <!--内容-->
    <cell v-for="(item, index) in runs" v-bind:key="index">

      <div class="list_bg" v-if="item.apiName">
        <VRunTrustHistory class="cell" :item="item"></VRunTrustHistory>
      </div>

      <div class="genduo-bg" v-else>
        <text class="font22 text3">{{T('没有更多数据')}}</text>
      </div>
    </cell>
  </list>
</template>

<script>


//组件
import VRunContractHistory from '@/run/view/VRunContractHistory.vue' 
import VRunStockHistory from '@/run/view/VRunStockHistory.vue' 
import VRunTrustHistory from '@/run/view/VRunTrustHistory.vue' 

//功能
import modal from "@/_js/modal";
import math from "@/_js/math";
import Config from "@/_js/config";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T("执行历史"));

export default {

  components: {
    VRunContractHistory,
    VRunStockHistory,
    VRunTrustHistory,
  },

  data() {
    return {
      T:T,
      Config:Config,
      math:math,
      
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载
      pageNo:0, //页码
      pageMax:false, //turn最大页面
      runs:[], //策略列表
    };
  },

  mounted() {
    this.httpTrusts();
  },
  
  methods: {

    //初始化数据
    initDatas(datas) {

      for (let index = 0; index < datas.length; index++) {
        var map = datas[index];
        var length = math.getCoin(map.investCoin);
        map.investCoinNum = math.xiaoshu(map.investCoinNum, length, 2); 
      }

      return datas;
    }, 

    /********************************** HTTP*/
    //策略列表-刷新
    httpTrusts() {
      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var param = {'pageNo':1};
      weexHttp.post("foundation/queryFundExecuteHistoryList",param,true,(data) => {
          this.isRefresh = false;

          if (data.status == 200) {
            data = data.data;

            this.runs = this.initDatas(data);
            this.pageNo = 1;
            this.pageMax = this.runs.length < 10;
            if(this.runs.length < 10) this.runs.push({});
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },

    //策略列表-加载
    httpTrustsLoading() {
      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var param = {'pageNo': this.pageNo + 1};
      weexHttp.post("foundation/queryFundExecuteHistoryList",param,true,(data) => {
        this.isLoadinging = false;

        if (data.status == 200) {
          data = data.data;

          var runs = this.initDatas(data);
          this.runs.push(...runs);
          this.pageNo++;
          this.pageMax = runs.length < 10;
          if(runs.length < 10) this.runs.push({});
        } else {
          modal.toast(data.msg);
        }
      });
    },

    /********************************** 点击触发*/
    //菜单点击
    menuClick(menu){
      this.menu = menu;
    },
  },
};

</script>


<style src="@/_css/style.css"></style>
<style scoped>
/*********************** 列表*/
.list {
  margin-top: 20px;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
}
.cell {
  width: 710px;
  margin-top: 20px;
  margin-left: 20px;
  margin-bottom: 20px;
}

/*********************** 刷新*/
.refresh {
  width: 750;
  flex-direction: row;
  justify-content: center;
}
.load {
  margin-top: 16px;
  height: 40px;
  width: 40px;
}
.genduo-bg {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 750px;
  height: 100px;
}
</style>